/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects.smartidlc;

public class ConsoleMessageReporter implements IMessageReporter {

	private CompilerOptions options;

	public ConsoleMessageReporter(CompilerOptions options) {
		this.options = options;
	}
	
	@Override
	public void onError(String message) {
		System.err.println(message);
	}

	@Override
	public void onMessage(String message) {
		System.out.println(message);	
	}

	@Override
	public void onWarning(String message) {
		onError ( message );
	}

	private void printStackTrace(Exception ex) {
		System.err.println("Stack trace: ");
		System.err.println("--------------------------------------------------------------------");
		ex.printStackTrace();
		System.err.println("--------------------------------------------------------------------");
		System.err.println("End of stack trace: ");
	}
	
	@Override
	public void onError(Exception ex) {
		printStackTrace(ex);
	}

	@Override
	public void onVerboseMessage(String message) {
		if ( options.isVerboseOutput() )
			onMessage ( message );
	}
	
	@Override
	public void onVeryVerboseMessage(String message) {
		if ( options.isVeryVerboseOutput() )
			onMessage ( message );
	}	

	@Override
	public boolean isVerboseOutputEnabled() {
		return options.isVerboseOutput();
	}
	
	@Override
	public boolean isVeryVerboseOutputEnabled() {
		return options.isVeryVerboseOutput();
	}
	
	
}
